#pragma once

#include<iostream>
#include<vector>
#include<unistd.h>

//函数指针
typedef void(*fun_t)();

void PrintLog()
{
    std::cout<<"pid:"<<getpid()<<" 打印日志任务，正在被执行"<<std::endl;
}

void InsertMySQL()
{
    std::cout<<"pid:"<<getpid()<<" 执行数据库任务，正在被执行"<<std::endl;
}

void NetRequest()
{
    std::cout<<"pid:"<<getpid()<<" 执行网络请求任务，正在被执行"<<std::endl;
}

//数字对应的指令
#define COMMAND_LOG 1
#define COMMAND_MYSQL 2
#define COMMAND_REQUEST 3

class Task
{
public:
    Task()
    {
        funcs.push_back(PrintLog);
        funcs.push_back(InsertMySQL);
        funcs.push_back(NetRequest);
    }

    void Execute(int command)
    {
        //commend是执行第几个命令
        if(command>=0&&command<funcs.size())
        {
            funcs[command]();
        }
    }

    ~Task()
    {

    }
public:
    std::vector<fun_t>funcs;
};